{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "## 识别小猫和小狗"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "data": {
      "text/plain": "(torch.Size([3, 32, 32, 50000]), torch.Size([3, 32, 32, 10000]))"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from torchvision import datasets,transforms\n",
    "import torch\n",
    "data_path = '../data2/p1ch7/'\n",
    "cifiar10 = datasets.CIFAR10(data_path,train=True,download=False,transform=transforms.ToTensor())\n",
    "cifiar10_val = datasets.CIFAR10(data_path,train=False,transform=transforms.ToTensor())\n",
    "a=torch.stack([imgs for imgs,_ in cifiar10],dim=3)\n",
    "b=torch.stack([imgs for imgs,_ in cifiar10_val],dim=3)\n",
    "a.shape,b.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T05:24:19.172076900Z",
     "start_time": "2023-10-22T05:23:34.117841100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "(tensor([0.4914, 0.4822, 0.4465]), tensor([0.2470, 0.2435, 0.2616]))"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cifiar10_norm_mean = a.view(3,-1).mean(dim=1)\n",
    "cifiar10_norm_std = a.view(3,-1).std(dim=1)\n",
    "\n",
    "cifiar10_norm_mean,cifiar10_norm_std"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T05:31:28.518125100Z",
     "start_time": "2023-10-22T05:31:27.363126300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "(tensor([0.4914, 0.4822, 0.4465]), tensor([0.2467, 0.2429, 0.2616]))"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cifiar10_val_norm_mean = b.view(3,-1).mean(dim=1)\n",
    "cifiar10_val_norm_std = b.view(3,-1).std(dim=1)\n",
    "\n",
    "cifiar10_val_norm_mean,cifiar10_val_norm_std"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T05:29:17.625711Z",
     "start_time": "2023-10-22T05:29:17.315704200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 640x480 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAojElEQVR4nO3df3TU9Z3v8VcgMAGSDKZAZmJizGqwKj+2ikKoP4CWXLO3XhW71x97e2G7dUHBUy56tejZNdueQ6yuXL2HSm23y8KtFO+uQu2KSnqAYA9Sg4WSC6xiCRJqxjSUZJJIJga+9w/LaCTA9w3z5ZNMno9z5hwz8+adz3e+38zL7/x4T4bneZ4AAHBgkOsFAAAGLkIIAOAMIQQAcIYQAgA4QwgBAJwhhAAAzhBCAABnCCEAgDOZrhfwecePH9cHH3ygnJwcZWRkuF4OAMDI8zy1tbWpoKBAgwad/lynz4XQBx98oKKiItfLAACco4aGBhUWFp62JrAQevbZZ/Xkk0+qsbFRV155pZ5++mldf/31Z/x3OTk5kj5ZfG5ublDL64f+YKz/rf/SI+tsrd/6pan8D+sbfdfu32BbSssHtnqLDw21B429u4317xtqdxl7v2eotT43cbGhtt7Y2+LLxvoRxvorDbXXhWy9Dyb81/67rbWuMdb7lZD0v/Tp4/npBBJCL7zwghY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YLKapU6fq8OHDrpcWiBP7Lt33qyRVVFTo+eef18aNG/XUU0+ptrZWM2bMUCIR5HdLBMfzPC1atEjXXXedxo0bJyk992dv2ymlz/6sq6tTdna2QqGQ5s2bp7Vr1+qKK6447/uyz03RPpXPfq2D9MkB8vnr+rOKiorkf48fP15lZWW65JJLtHLlSi1atMjhyoKV7vtVku64447kf48bN06TJk1ScXGxXnnlFc2aNcvhys7OggULtGvXLv3qV7866bZ02p+n2s502Z+XXXaZdu7cqZaWFr344ouaPXu2ampqkrefr33Z58+ERo0apcGDB5+UwE1NTScldToZMWKExo8fr3379rleSiBOvPNvoO1XSYpGoyouLu6X+/b+++/Xyy+/rE2bNvX4ypV025+n2s7e9Nf9OXToUF166aWaNGmSqqqqNHHiRD3zzDPnfV/2+RAaOnSorr76alVXV/e4vrq6WlOnTnW0quAlEgnt3btX0WjU9VICUVJSokgk0mO/dnV1qaamJq33qyQdPnxYDQ0N/Wrfep6nBQsW6KWXXtLGjRtVUlLS4/Z02Z9n2s7e9Mf92RvP85RIJM7/vkz5Wx0CsGbNGm/IkCHeT37yE2/Pnj3ewoULvREjRngHDhxwvbSUeeCBB7zNmzd7+/fv97Zt2+Z97Wtf83Jycvr1Nra1tXk7duzwduzY4Unyli5d6u3YscN7//33Pc/zvMcff9wLh8PeSy+95NXV1Xl33XWXF41GvXg87njlNqfbzra2Nu+BBx7wtm7d6tXX13ubNm3yysrKvAsvvLBfbee9997rhcNhb/PmzV5jY2Py8tFHHyVr0mF/nmk702V/Ll682NuyZYtXX1/v7dq1y3vkkUe8QYMGeRs2bPA87/zuy34RQp7neT/4wQ+84uJib+jQod5VV13V4y2T6eCOO+7wotGoN2TIEK+goMCbNWuWt3v3btfLOiebNm3yJJ10mT17tud5n7yt97HHHvMikYgXCoW8G264waurq3O76LNwuu386KOPvPLycm/06NHekCFDvIsuusibPXu2d/DgQdfLNult+yR5K1asSNakw/4803amy/785je/mXw8HT16tPeVr3wlGUCed373JV/lAABwps+/JgQASF+EEADAGUIIAOAMIQQAcIYQAgA4QwgBAJwhhAAAzhBCAABnCCEAgDOEEADAGUIIAOAMIQQAcOb/A4rjeoI/W+mmAAAAAElFTkSuQmCC"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cat\n"
     ]
    }
   ],
   "source": [
    "from torchvision import datasets,transforms\n",
    "data_path = '../data2/p1ch7/'\n",
    "cifiar10 = datasets.CIFAR10(data_path,train=True,download=False,transform=transforms.Compose([\n",
    "    transforms.ToTensor(),\n",
    "    transforms.Normalize((0.4914,0.4822,0.4465),(0.2470,0.2435,0.2616))\n",
    "]))\n",
    "cifiar10_val = datasets.CIFAR10(data_path,train=False,transform=transforms.Compose([\n",
    "    transforms.ToTensor(),\n",
    "    transforms.Normalize((0.4914,0.4822,0.4465),(0.2470,0.2435,0.2616))\n",
    "]))\n",
    "\n",
    "label_map = {3:0,5:1}\n",
    "class_names = ['cat','dog']\n",
    "cifiar2 = [(img,label_map[label])for img,label in cifiar10 if label in [3,5]]\n",
    "cifiar2_val = [(img,label_map[label])for img,label in cifiar10_val if label in [3,5]]\n",
    "\n",
    "img,label = cifiar2[99]\n",
    "import matplotlib.pyplot as plt\n",
    "plt.imshow(img.permute(1,2,0))\n",
    "plt.show()\n",
    "print(class_names[label])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T08:46:25.786533300Z",
     "start_time": "2023-10-22T08:45:42.428510Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [],
   "source": [
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "import torch\n",
    "class Net(nn.Module):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.conv1 = nn.Conv2d(3,32,kernel_size=3,padding=1)\n",
    "        self.conv2 = nn.Conv2d(32,16,kernel_size=3,padding=1)\n",
    "        self.fc1 = nn.Linear(16*8*8,32)\n",
    "        self.fc2 = nn.Linear(32,2)\n",
    "\n",
    "    def forward(self,x):\n",
    "        out = F.max_pool2d(torch.tanh(self.conv1(x)),2)\n",
    "        out = F.max_pool2d(torch.tanh(self.conv2(out)),2)\n",
    "        out = out.view(-1,16*8*8)\n",
    "        out = torch.tanh(self.fc1(out))\n",
    "        out = self.fc2(out)\n",
    "        return out"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T08:47:21.618763900Z",
     "start_time": "2023-10-22T08:47:21.603767800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "import datetime\n",
    "def train_loop(n_epochs,model,optimizer,loss_fn,train_loader):\n",
    "    for epoch in range(n_epochs+1):\n",
    "        loss_train=0.0\n",
    "        for imgs,labels in train_loader:\n",
    "            imgs,labels= imgs.cuda(),labels.cuda()\n",
    "            outputs = model(imgs)\n",
    "            loss = loss_fn(outputs,labels)\n",
    "            optimizer.zero_grad()\n",
    "            loss.backward()\n",
    "            optimizer.step()\n",
    "\n",
    "            loss_train+=loss.item()\n",
    "        if epoch==1 or epoch%10==0:\n",
    "            print('{}, Epoch:{}, 训练损失:{}'.format(datetime.datetime.now(),epoch,loss_train/len(train_loader)))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T08:47:22.483653900Z",
     "start_time": "2023-10-22T08:47:22.469617700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-22 16:48:04.761076, Epoch:0, 训练损失:0.6614801526828936\n",
      "2023-10-22 16:48:05.555046, Epoch:1, 训练损失:0.6270556802962236\n",
      "2023-10-22 16:48:12.955045, Epoch:10, 训练损失:0.45567226979383235\n",
      "2023-10-22 16:48:21.423085, Epoch:20, 训练损失:0.25915344491316256\n",
      "2023-10-22 16:48:30.071045, Epoch:30, 训练损失:0.0997826070020533\n",
      "2023-10-22 16:48:38.193049, Epoch:40, 训练损失:0.07876798498094272\n",
      "2023-10-22 16:48:46.757087, Epoch:50, 训练损失:0.007174373992531898\n",
      "2023-10-22 16:48:55.908060, Epoch:60, 训练损失:0.0029480367384340828\n",
      "2023-10-22 16:49:04.869063, Epoch:70, 训练损失:0.0019253902747162327\n",
      "2023-10-22 16:49:13.461067, Epoch:80, 训练损失:0.0014149930406358853\n",
      "2023-10-22 16:49:21.486097, Epoch:90, 训练损失:0.001108119873386351\n",
      "2023-10-22 16:49:29.527044, Epoch:100, 训练损失:0.0009059218040431677\n"
     ]
    }
   ],
   "source": [
    "model = Net().cuda()\n",
    "loss_fn = nn.CrossEntropyLoss()\n",
    "import torch.optim as optim\n",
    "optimizer = optim.SGD(model.parameters(),lr=0.1)\n",
    "train_loader = torch.utils.data.DataLoader(cifiar2,shuffle=False,batch_size=64)\n",
    "train_loop(n_epochs=100,model=model,loss_fn=loss_fn,optimizer=optimizer,train_loader=train_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T08:49:29.562045200Z",
     "start_time": "2023-10-22T08:47:23.586628200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [],
   "source": [
    "def test_loop(model,test_loader):\n",
    "    correct = 0\n",
    "    total = 0\n",
    "    with torch.no_grad():\n",
    "        for imgs,labels in test_loader:\n",
    "            imgs,labels=imgs.cuda(),labels.cuda()\n",
    "            outputs = model(imgs)\n",
    "            _,preds = torch.max(outputs,dim=1)\n",
    "            total+=labels.shape[0]\n",
    "            correct+=int((labels==preds).sum())\n",
    "    print('测试集精度:{:.3f}%'.format(100*correct/total))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T08:50:17.502119200Z",
     "start_time": "2023-10-22T08:50:17.486131500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集精度:70.050%\n"
     ]
    }
   ],
   "source": [
    "test_loader = torch.utils.data.DataLoader(cifiar2_val,shuffle=False,batch_size=64)\n",
    "test_loop(model,test_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T08:50:18.250114200Z",
     "start_time": "2023-10-22T08:50:17.958114800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "outputs": [],
   "source": [
    "class NetDrop(nn.Module):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.conv1 = nn.Conv2d(3,32,kernel_size=3,padding=1)\n",
    "        self.conv1_drop = nn.Dropout2d(p=0.4)\n",
    "        self.conv2 = nn.Conv2d(32,16,kernel_size=3,padding=1)\n",
    "        self.conv2_drop = nn.Dropout2d(p=0.4)\n",
    "        self.fc1 = nn.Linear(16*8*8,32)\n",
    "        self.fc2 = nn.Linear(32,2)\n",
    "\n",
    "    def forward(self,x):\n",
    "        out = F.max_pool2d(torch.tanh(self.conv1(x)),2)\n",
    "        out = self.conv1_drop(out)\n",
    "        out = F.max_pool2d(torch.tanh(self.conv2(out)),2)\n",
    "        out = self.conv2_drop(out)\n",
    "        out = out.view(-1,16*8*8)\n",
    "        out = torch.tanh(self.fc1(out))\n",
    "        out = self.fc2(out)\n",
    "        return out"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:13:25.070740100Z",
     "start_time": "2023-10-22T06:13:25.036741500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-22 14:15:05.436040, Epoch:0, 训练损失:0.6867446550138437\n",
      "2023-10-22 14:15:06.297044, Epoch:1, 训练损失:0.6709864896953486\n",
      "2023-10-22 14:15:13.779041, Epoch:10, 训练损失:0.6270856143562658\n",
      "2023-10-22 14:15:22.062081, Epoch:20, 训练损失:0.6006459988606204\n",
      "2023-10-22 14:15:30.338045, Epoch:30, 训练损失:0.5943699875834642\n",
      "2023-10-22 14:15:39.040041, Epoch:40, 训练损失:0.5824804552801096\n",
      "2023-10-22 14:15:47.195040, Epoch:50, 训练损失:0.5793364471311022\n",
      "2023-10-22 14:15:55.368040, Epoch:60, 训练损失:0.5711532495204051\n",
      "2023-10-22 14:16:03.576074, Epoch:70, 训练损失:0.5699902224312922\n",
      "2023-10-22 14:16:11.745055, Epoch:80, 训练损失:0.5562565913245936\n",
      "2023-10-22 14:16:19.946054, Epoch:90, 训练损失:0.5615205387021326\n",
      "2023-10-22 14:16:28.141044, Epoch:100, 训练损失:0.5543444570462415\n"
     ]
    }
   ],
   "source": [
    "model_drop = NetDrop().cuda()\n",
    "optimizer = optim.SGD(model_drop.parameters(),lr=0.5)\n",
    "train_loop(n_epochs=100,model=model_drop,loss_fn=loss_fn,optimizer=optimizer,train_loader=train_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:16:28.157043400Z",
     "start_time": "2023-10-22T06:15:03.524042Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集精度:0.650\n"
     ]
    }
   ],
   "source": [
    "test_loop(model_drop.eval(),test_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:17:06.554377900Z",
     "start_time": "2023-10-22T06:17:06.208387500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "outputs": [],
   "source": [
    "class NetBatch(nn.Module):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.conv1 = nn.Conv2d(3,32,kernel_size=3,padding=1)\n",
    "        self.batch_norm1 = nn.BatchNorm2d(num_features=32)\n",
    "        self.conv2 = nn.Conv2d(32,16,kernel_size=3,padding=1)\n",
    "        self.batch_norm2 = nn.BatchNorm2d(num_features=16)\n",
    "        self.fc1 = nn.Linear(16*8*8,32)\n",
    "        self.fc2 = nn.Linear(32,2)\n",
    "\n",
    "    def forward(self,x):\n",
    "        out = self.batch_norm1(self.conv1(x))\n",
    "        out = F.max_pool2d(torch.tanh(out),2)\n",
    "        out = self.batch_norm2(self.conv2(out))\n",
    "        out = F.max_pool2d(torch.tanh(out),2)\n",
    "        out = out.view(-1,16*8*8)\n",
    "        out = torch.tanh(self.fc1(out))\n",
    "        out = self.fc2(out)\n",
    "        return out"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:18:11.097105700Z",
     "start_time": "2023-10-22T06:18:11.072081Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-22 14:34:27.163572, Epoch:0, 训练损失:0.6698751973498399\n",
      "2023-10-22 14:34:28.164535, Epoch:1, 训练损失:0.6467210684612299\n",
      "2023-10-22 14:34:36.821576, Epoch:10, 训练损失:0.5361412431404089\n",
      "2023-10-22 14:34:46.394534, Epoch:20, 训练损失:0.4467142250887148\n",
      "2023-10-22 14:34:55.977564, Epoch:30, 训练损失:0.37409520557351933\n",
      "2023-10-22 14:35:05.581563, Epoch:40, 训练损失:0.30868516046150474\n",
      "2023-10-22 14:35:15.218535, Epoch:50, 训练损失:0.24155020652113446\n",
      "2023-10-22 14:35:24.873541, Epoch:60, 训练损失:0.1822414533680032\n",
      "2023-10-22 14:35:34.495564, Epoch:70, 训练损失:0.1323772276140702\n",
      "2023-10-22 14:35:44.057535, Epoch:80, 训练损失:0.09213649958467028\n",
      "2023-10-22 14:35:53.670547, Epoch:90, 训练损失:0.06166703353641899\n",
      "2023-10-22 14:36:03.586537, Epoch:100, 训练损失:0.041955455117354726\n"
     ]
    }
   ],
   "source": [
    "model_batch = NetBatch().cuda()\n",
    "optimizer = optim.SGD(model_batch.parameters(),lr=0.01)\n",
    "train_loop(n_epochs=100,model=model_batch,loss_fn=loss_fn,optimizer=optimizer,train_loader=train_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:36:03.593538100Z",
     "start_time": "2023-10-22T06:34:25.973537700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集精度:0.708\n"
     ]
    }
   ],
   "source": [
    "test_loop(model_batch.eval(),test_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:36:03.732544Z",
     "start_time": "2023-10-22T06:36:03.598537600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集精度:0.952\n"
     ]
    }
   ],
   "source": [
    "test_loop(model_batch.eval(),train_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:36:05.645702Z",
     "start_time": "2023-10-22T06:36:04.845659100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 640x480 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAlDElEQVR4nO3df3TU9Z3v8ddAyCSQZABDMhMT06jBggGu/BCSBQlsyRpPuSK6F2XXC7f3uqLgORx0bZE/zPbcJSy7cnQPlm6tl8JWFvZu1aUFlfQAAQu0gULJIuvFEiRUYiQLmSSQiQPf+0frrJFfnw/M8EmG5+OcOYfMvPPO+8s35MU3mbzH53me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sXezt27PAaGhq8gwcPei+88ILXp08fb8uWLZ7n3dhz2StCyPM879VXX/UKCwu91NRUb/To0d2eMpkMZs2a5YVCIa9fv35eXl6eN3PmTO/QoUOux7ou27Zt8yRddJszZ47neb9/Wu+LL77oBYNBz+/3e/fdd59XX1/vduhrcKXjPHv2rFdRUeENGTLE69evn3fbbbd5c+bM8Y4fP+56bCuXOj5J3urVq2M1yXA+r3acyXI+v/Wtb8W+ng4ZMsT74z/+41gAed6NPZe8lAMAwJke/zMhAEDyIoQAAM4QQgAAZwghAIAzhBAAwBlCCADgDCEEAHCGEAIAOEMIAQCcIYQAAM4QQgAAZwghAIAz/x92Vbde7EF/sgAAAABJRU5ErkJggg=="
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dog\n"
     ]
    }
   ],
   "source": [
    "img,label = cifiar2_val[99]\n",
    "import matplotlib.pyplot as plt\n",
    "plt.imshow(img.permute(1,2,0))\n",
    "plt.show()\n",
    "print(class_names[label])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:23:06.849526800Z",
     "start_time": "2023-10-22T06:23:06.632490300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "outputs": [
    {
     "data": {
      "text/plain": "'dog'"
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = model_batch(img.cuda().unsqueeze(0))\n",
    "_,pred=torch.max(output,dim=1)\n",
    "class_names[pred]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T06:24:56.929641100Z",
     "start_time": "2023-10-22T06:24:56.668877500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [],
   "source": [
    "class NetDepth(nn.Module):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.conv1 = nn.Conv2d(3,32,kernel_size=3,padding=1)\n",
    "        self.conv1_drop = nn.Dropout(p=0.4)\n",
    "        self.conv2 = nn.Conv2d(32,16,kernel_size=3,padding=1)\n",
    "        self.conv2_drop = nn.Dropout(p=0.4)\n",
    "        self.fc1 = nn.Linear(16*8*8,32)\n",
    "        self.fc1_drop = nn.Dropout(p=0.4)\n",
    "        self.fc2 = nn.Linear(32,16)\n",
    "        self.fc3 = nn.Linear(16,2)\n",
    "\n",
    "    def forward(self,x):\n",
    "        out = F.max_pool2d(torch.tanh(self.conv1(x)),2)\n",
    "        out = self.conv1_drop(out)\n",
    "        out = F.max_pool2d(torch.tanh(self.conv2(out)),2)\n",
    "        out = self.conv2_drop(out)\n",
    "        out = out.view(-1,16*8*8)\n",
    "        out = torch.tanh(self.fc1(out))\n",
    "        out = self.fc1_drop(out)\n",
    "        out = torch.tanh(self.fc2(out))\n",
    "        out = self.fc3(out)\n",
    "        return out"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T08:57:18.467592400Z",
     "start_time": "2023-10-22T08:57:18.457592400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-22 17:03:42.380306, Epoch:0, 训练损失:0.6706279702247329\n",
      "2023-10-22 17:03:43.223316, Epoch:1, 训练损失:0.6394909316567099\n",
      "2023-10-22 17:03:51.002311, Epoch:10, 训练损失:0.5542440450495216\n",
      "2023-10-22 17:03:59.423309, Epoch:20, 训练损失:0.5255787165681268\n",
      "2023-10-22 17:04:07.844333, Epoch:30, 训练损失:0.5018934852378384\n",
      "2023-10-22 17:04:16.359305, Epoch:40, 训练损失:0.4876923428219595\n",
      "2023-10-22 17:04:24.754305, Epoch:50, 训练损失:0.4806178677233921\n",
      "2023-10-22 17:04:33.179341, Epoch:60, 训练损失:0.4740488109694924\n",
      "2023-10-22 17:04:41.558322, Epoch:70, 训练损失:0.46313815853398316\n",
      "2023-10-22 17:04:50.032303, Epoch:80, 训练损失:0.45885566427449515\n",
      "2023-10-22 17:04:58.781306, Epoch:90, 训练损失:0.4601297653784418\n",
      "2023-10-22 17:05:07.176308, Epoch:100, 训练损失:0.4557166619665304\n"
     ]
    }
   ],
   "source": [
    "import torch.optim as optim\n",
    "model = NetDepth().cuda()\n",
    "optimizer = optim.SGD(model.parameters(),lr=0.2)\n",
    "loss_fn = nn.CrossEntropyLoss()\n",
    "train_loop(n_epochs=100,model=model,optimizer=optimizer,loss_fn=loss_fn,train_loader=train_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T09:05:07.182325300Z",
     "start_time": "2023-10-22T09:03:41.145307500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集精度:76.250%\n"
     ]
    }
   ],
   "source": [
    "test_loop(model.eval(),test_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T09:11:37.032115100Z",
     "start_time": "2023-10-22T09:11:36.742117200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集精度:84.630%\n"
     ]
    }
   ],
   "source": [
    "test_loop(model.eval(),train_loader)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T09:11:29.032993900Z",
     "start_time": "2023-10-22T09:11:27.951959800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 640x480 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIH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CEAgDeEEADAG0IIAODNkAmhp556SiUlJcrIyNA111yjPXv2+F7SgKqqqlJaWlq/LRKJ+F7WBdm9e7cWLlyogoICpaWl6cUXX+x3fRAEqqqqUkFBgTIzMzV37lwdOnTIz2IvwBft59KlS087trNnz/az2PNUXV2tmTNnKhwOKy8vTzfffLPeeuutfjWpcDxd9jMVjuf69es1bdq0xBtSy8vL9corrySuv5jHckiE0ObNm7VixQo98sgjOnDggK677jpVVlbq/fff9720AXXllVeqqakpsdXX1/te0gXp6urS9OnTtW7dujNev2bNGq1du1br1q1TXV2dIpGIFixYoI6Ojou80gvzRfspSTfeeGO/Y/vyyy9fxBVeuNraWi1btkz79u1TTU2N+vr6VFFRoa6u/xyBmQrH02U/paF/PAsLC/XYY49p//792r9/v+bPn6+bbropETQX9VgGQ8DXvva14N577+132Ve/+tXg7//+7z2taOA9+uijwfTp030vI2kkBVu2bEl8ferUqSASiQSPPfZY4rKenp4gJycn+OEPf+hhhQPj8/sZBEGwZMmS4KabbvKynmRpbm4OJAW1tbVBEKTu8fz8fgZBah7PIAiC8ePHB//0T/900Y/loD8T6u3t1RtvvKGKiop+l1dUVGjv3r2eVpUcR48eVUFBgUpKSnT77bfrnXfe8b2kpGloaFAsFut3XEOhkG644YaUO66StGvXLuXl5Wny5Mm6++671dzc7HtJF6StrU2SNGHCBEmpezw/v5+fSaXjefLkSW3atEldXV0qLy+/6Mdy0IfQ8ePHdfLkSeXn5/e7PD8/X7FYzNOqBt6sWbP07LPPatu2bfrJT36iWCymOXPmqKWlxffSkuKzY5fqx1WSKisr9dxzz2nHjh16/PHHVVdXp/nz5yseN36+0SARBIFWrlypa6+9VmVlZZJS83ieaT+l1Dme9fX1ysrKUigU0r333qstW7boiiuuuOjHctBN0T6bP/5YB+nTG8jnLxvKKisrE/+eOnWqysvL9ZWvfEUbNmzQypUrPa4suVL9uErS4sWLE/8uKyvTjBkzVFxcrK1bt2rRokUeV3Z+li9froMHD+q111477bpUOp5n289UOZ6XX3653nzzTbW2tuqXv/yllixZotra2sT1F+tYDvozodzcXI0cOfK0BG5ubj4tqVPJ2LFjNXXqVB09etT3UpLis1f+DbfjKknRaFTFxcVD8tg+8MADeumll7Rz585+H7mSasfzbPt5JkP1eI4ePVqTJk3SjBkzVF1drenTp+vJJ5+86Mdy0IfQ6NGjdc0116impqbf5TU1NZozZ46nVSVfPB7XkSNHFI1GfS8lKUpKShSJRPod197eXtXW1qb0cZWklpYWNTY2DqljGwSBli9frhdeeEE7duxQSUlJv+tT5Xh+0X6eyVA8nmcSBIHi8fjFP5YD/lKHJNi0aVMwatSo4Omnnw4OHz4crFixIhg7dmzw7rvv+l7agPn2t78d7Nq1K3jnnXeCffv2BX/5l38ZhMPhIb2PHR0dwYEDB4IDBw4EkoK1a9cGBw4cCN57770gCILgscceC3JycoIXXnghqK+vD+64444gGo0G7e3tnlduc6797OjoCL797W8He/fuDRoaGoKdO3cG5eXlwSWXXDKk9vO+++4LcnJygl27dgVNTU2J7cSJE4maVDieX7SfqXI8V61aFezevTtoaGgIDh48GDz88MPBiBEjgu3btwdBcHGP5ZAIoSAIgh/84AdBcXFxMHr06ODqq6/u95LJVLB48eIgGo0Go0aNCgoKCoJFixYFhw4d8r2sC7Jz585A0mnbkiVLgiD49GW9jz76aBCJRIJQKBRcf/31QX19vd9Fn4dz7eeJEyeCioqKYOLEicGoUaOCSy+9NFiyZEnw/vvv+162yZn2T1LwzDPPJGpS4Xh+0X6myvH827/928Tj6cSJE4M//dM/TQRQEFzcY8lHOQAAvBn0zwkBAFIXIQQA8IYQAgB4QwgBALwhhAAA3hBCAABvCCEAgDeEEADAG0IIAOANIQQA8IYQAgB4QwgBALz5fzHoh8P5XvLDAAAAAElFTkSuQmCC"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": "'cat'"
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img,label = cifiar2_val[532]\n",
    "plt.imshow(img.permute(1,2,0))\n",
    "plt.show()\n",
    "class_names[label]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T09:18:26.538084100Z",
     "start_time": "2023-10-22T09:18:26.344080200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "outputs": [
    {
     "data": {
      "text/plain": "'cat'"
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model_predict = model.eval()\n",
    "output = model_predict(img.cuda().unsqueeze(0))\n",
    "_,pred = torch.max(output,dim=1)\n",
    "class_names[pred]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T09:18:29.943016300Z",
     "start_time": "2023-10-22T09:18:29.925973900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "outputs": [
    {
     "data": {
      "text/plain": "2000"
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(cifiar2_val)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-22T09:18:38.131523800Z",
     "start_time": "2023-10-22T09:18:38.116528Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
